$(function(){
	
	// 定义底部保存，清空，取消按钮
	$('#SingleChoiceAdd').dialog({
		buttons : [ {
			text : '保存',
			iconCls : 'icon-save',
			handler : function() {
				$('#ff').form('submit', {
					onSubmit : function(param) {
						alert($("#SingleChoice_getTk").val())
						$.post("../exam/SingleChoiceAdd?qbId="+$("#SingleChoice_getTk").val()+"&answer="+$("#s6").val()+"&a="+$("#s2").val()+"&b="+$("#s3").val()+"&c="+$("#s4").val()+"&d="+$("#s5").val()+"&examQuestion="+$("#s1").val(),function(){
							$('#SingleChoice').datagrid('reload');
						})
						$("#SingleChoiceAdd").window("close");
					},
					success : function(data) {
						$('#SingleChoiceAdd').datagrid('load');
					}
				});

			}
		}, {
			text : '清空',
			iconCls : 'icon-clear',
			handler : function() {
				$('#ff').form('clear');
			}
		}, {
			text : '取消',
			iconCls : 'icon-cancel',
			handler : function() {
				$("#SingleChoiceAdd").window("close");
			}
		} ]
	});
	
	
	wjl_editIndex=undefined;
	var url='../exam/getAllSingleChoice';
	$('#SingleChoice').datagrid({
	    url:url,
	    columns:[[
	    	{field:'singleChoiceId',title:"编号",width:50,align:'center'},
	    	{field:'qb_id',title:"题库",width:50,align:'center',
	    		formatter: function(value,row,index){
					if (row.questionBank){
						return row.questionBank.qbName;
					} else {
						return value;
					}
				}},
			{field:'examQuestion',title:"考题",width:200,align:'center'},
			{field:'answer',title:"答案",width:50,align:'center'},
			{field:'a',title:"A",width:80,align:'center'},
			{field:'b',title:"B",width:80,align:'center'},
			{field:'c',title:"C",width:80,align:'center'},
			{field:'d',width:80,title:"D",align:'center'},
			{field:'createPeople',title:"创建人",width:80,align:'center'},
			{field:'createDate',title:"创建时间",width:150,align:'center'},
			{field:'',width:100,align:'center',checkbox:true}
	    ]],
		fit:true,
		method:'get',
		toolbar:'#single_choice_tb',
		rownumbers:true,
		width: 700,
		height: 250,
		//显示分页栏
		pagination:true,
		//设置每页大小
		pageSize:5,
		//可选的每页大小
		pageList:[5,8,10],
		
		});
	
	
	
	
	$("#tK").combobox({
	    url:'../exam/getAllquestionBank',
	    valueField:'qbId',
	    textField:'qbName'
	});
	$("#SingleChoiceSearch").bind('click',function(){
		var qbId=$("#tK").val();
		var examQuestion=$("#SingleQuestionName").val();
		if(qbId==""){
			qbId=0;
		}
		if(examQuestion==""){
			examQuestion="error";
		}
		alert(examQuestion);
		var value=qbId+","+examQuestion;
		$('#SingleChoice').datagrid('load',"../exam/SingleChoiceSearch?value="+value);
	})
});

function add(){
	$("#SingleChoiceAdd").window("open");
	$('#SingleChoice_getTk').combobox({
	    url:'../exam/getAllquestionBank',
	    valueField:'qbId',
	    textField:'qbName'
	});
}


//删除
function remove(){
	var rows = $('#SingleChoice').datagrid('getSelections');
	if(rows.length > 0){
		$.messager.confirm('请确认','您确定要删除当前所有选中的项目吗？',function(r){
			if(r){
				var singleChoiceIds = [];
				for(var i = 0; i < rows.length; i++){
					debugger;
						singleChoiceIds.push(rows[i].singleChoiceId)
					
				}
				alert(singleChoiceIds);
				$.post('../exam/deleteSingleChoice?value='+singleChoiceIds,function(){
					$('#SingleChoice').datagrid('reload');
				})
				
				wjl_editIndex = undefined;
			}
		})
	}else{
		$.messager.alert('提示','请选择要删除的记录！','error');
	}
}

//清空
function clear(){
	$("#single_choice_tb").find('input').val('');
}